<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>借钱贷</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <script src="./script/vue.min.js"></script>
    <style type="text/css">
        html,
        body {
            height: 100%;
        }

        #wrap {
            height: 100%;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-orient: vertical;
            -webkit-flex-flow: column;
            flex-flow: column;
        }

        #wrap div {
            width: 80%;
            margin: 20px 10%;
        }
    </style>
</head>

<body>
    <div id="wrap">
        <!-- <div style="margin-top:100px;" @click="goIndex1()" class="aui-btn aui-btn-primary">审核版2</div> -->
        <!-- <div class="aui-btn aui-btn-success" @click="goIndex2()">正式版2</div> -->
    </div>
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script src="./script/jquery.min.js"></script>
<script type="text/javascript">
    apiready = function() {
        init();
        var bMap = api.require('bMap');
        // $api.setStorage('phone2', '18670331964')
        var phone2 = $api.getStorage('phone2')
        if(phone2){
          bMap.getLocation({
              accuracy: '10m',
              autoStop: true,
              filter: 1
          }, function(ret, err) {
              if (ret.status) {
                  let lat = ret.lat;
                  let lon = ret.lon;
                  let location = lat + ',' + lon;
                  $.ajax({
                      type: "post",
                      url: "http://xhf.8jieyun.com/location/refresh",
                      dataType: 'json',
                      async: false,
                      data: {
                          phone: phone2,
                          location: location,
                      },
                      success: function(data) {
                        // alert(JSON.stringify(data))
                      }
                  });
              } else {
                  alert(err.code);
              }
          });
        }
        api.refreshHeaderLoadDone()
            // 再点一次退出应用
        api.setStatusBarStyle({
            style: 'dark'
        });
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            api.toast({
                msg: '再点一次退出应用',
                duration: 2000,
                location: 'bottom'
            });
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                api.closeWidget({
                    silent: true
                });
            });
            setTimeout(function() {
                exitApp();
            }, 2000)
        });
        var vm = new Vue({
            el: '#wrap',
            data: {},
            methods: {
            },
            mounted: function() {
                let phone2 = $api.getStorage('phone2')
                if (phone2) {
                    api.openWin({
                        name: 'home',
                        url: './html/audit/home.html',
                        slidBackEnabled: false
                    });
                } else {
                    api.openWin({
                        name: 'page1',
                        url: './html/audit/login.html',
                        slidBackEnabled: false
                    });
                };
            }
        })
    };


    function init() {
        api.addEventListener({
            name: 'smartupdatefinish'
        }, function(ret, err) {
            alert('更新完成');
            api.rebootApp();
        });
    };



    // 再点一次退出应用
    function exitApp() {
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
            api.toast({
                msg: '再点一次退出应用',
                duration: 2000,
                location: 'bottom'
            });
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err) {
                api.closeWidget({
                    silent: true
                });
            });
            setTimeout(function() {
                exitApp();
            }, 2000)
        });
    }
    setTimeout(function() {
        api.removeLaunchView();
    }, 500);
</script>

</html>
